<template>
	<view class="doclist">
		<!-- 头部 -->
		<view class="title">
			<view class="title_all flex-column-center font15 font-989898">
				<view>全部</view>
				<view>医生</view>
			</view>
			<view class="time_list">
				<view v-for="(item,index) in timeList" :key="index" class="time_listbos" @click="Ontime(item)">
					<view class="time_listbox flex-column-center"
						:class="item.show?'background_6bcbb6':'background_ffffff'">
						<view :class="item.show?'font-ffffff':'font-989898'" class="font11">{{item.weekStr}}
						</view>
						<view :class="item.show?'font-ffffff':'font-6bcbb6'" class="font13">{{item.nameStr}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 医生 -->
		<view class="doctor_bos" v-if="datalist.length>0">
			<!-- 循环 -->
			<view class="doctor_list flex-row-center" @click="Ondocyy(item)" v-for="(item,index) in datalist"
				:key="index">
				<image :src="http_img+item.doctor_info.img"></image>
				<view class="doctor_box flex-column-between">
					<view class="flex-row-between font15 font-323232 font-b">{{item.BCE03}}
						<view class="doctor_infobox flex-row-start">
							<!-- <text class="font-b">余号:{{item.AVAIlABLECOUNT}}</text> -->
							<view class="font-ffffff font12">￥{{item.BBY25}}</view>
						</view>
					</view>
					<view class="font14 font-646464">
						{{item.doctor_info.academic_title_name?item.doctor_info.academic_title_name.name:'暂无'}}
					</view>
					<view class="font13 font-989898 ellipsis">
						{{item.doctor_info.be_good_at?item.doctor_info.be_good_at:'暂无'}}
					</view>
				</view>
			</view>
		</view>
		<view v-else class="loading">暂无医生</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: null,
				timeList: [], //时间
				day: '', //请求的时间
				datalist: [], //请求的数据
				http_img: '', //前缀
			}
		},
		onLoad: function(options) {
			this.id = options.id
			this.allWeek()
			this.http_img = this.$store.state.http_img
		},
		methods: {
			//获取时间
			allWeek(dateTime) {
				var me = this;
				var sevenDays = [];
				var time = new Date().getTime();
				var dateStrList = [];
				for (var i = 0; i < 7; i++) {
					var date = new Date(time + i * 24 * 3600 * 1000);
					var weekTime = me.formatDate(date);
					var splitArr = weekTime.split(" ");
					var dateStr = splitArr[0];
					var weekStr = splitArr[1];
					var nameStr = splitArr[2];
					var dateObj = {};
					dateObj.dateStr = dateStr;
					dateObj.weekStr = weekStr;
					dateObj.nameStr = nameStr;
					sevenDays.push(dateObj);
				}
				this.timeList = sevenDays
				this.timeList.forEach(item => {
					item.show = false
				})
				this.timeList[0].show = true
				this.day = sevenDays[0].dateStr
				this.Onlist()
			},
			formatDate(date) {
				var year = date.getFullYear();
				var month = (date.getMonth() + 1);
				month = month <= 9 ? '0' + month : month;
				var day = date.getDate();
				day = day <= 9 ? '0' + day : day;
				var datetime = year + '-' + month + '-' + day;
				var datename = day + '号';
				var week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][date.getDay()];
				return datetime + ' ' + week + ' ' + datename;
			},
			//获取数据
			Onlist(date) {
				function isInteger(obj) {
					return obj % 1 === 0
				}
				this.$Http({
					url: 'getDoctorList',
					data: {
						room_his_id: this.id,
						date: this.day
					}
				}).then(res => {
					res.data.forEach(item => {
						item.BBY25 = Math.floor(item.BBY25 * 100) / 100
						if(isInteger(item.BBY25)){
							item.BBY25 = item.BBY25 +'.00'
						}
					})

					this.datalist = res.data
				})
			},
			//选择时间
			Ontime(e) {
				this.timeList.forEach(item => {
					item.show = false
					if (e.dateStr == item.dateStr) {
						item.show = true
					}
				})
				this.day = e.dateStr
				this.Onlist()
			},
			//前往医生预约
			Ondocyy(item) {
				uni.navigateTo({
					url: '/pagesA/his/docyy/docyy?id=' + item.BCE01 + '&day=' + this.day,
				});
			},
		}
	}
</script>

<style lang="less">
	@import url("style.less");
</style>
